<?php
global $database;
include("header.php");?> 
	<div id="form_container">
    	<div id="title_container">
            <div id="title">
                <p>Update Request</p>
            </div>
            <div id="title_link">
                <p><a href="javascript:history.back(-1)">Back</a></p>
            </div>
        </div>
    	<div id="form_content">
        <form method="POST" action="modProcess.php" style="overflow:auto;">
        	<ul>
			<?php
				if(!isset($_GET['id']) || !isset($_GET['orgID']))
				{
					echo "<p>Invalid URL</p>";
				}
				else
				{
					global $database, $session, $form;
					$id = $_GET['id'];
					$orgID = $_GET['orgID'];
					//mysql_query("UPDATE update_queue SET modAction='viewed' WHERE id='$id'");?>
            	<table id="modTable" cellpadding="0" cellpadding="0">
                    <thead>
                    	<th width="70px"></th>
                        <th width="300px">Requested Updates</th>
                        <th width="300px">Current Data</th>
                    </thead>
                    <tbody>
                        <?php
						$sql1 = mysql_query("SELECT * FROM ".TBL_UPDATE_QUEUE." WHERE id='$id'");
						$sql2 = mysql_query("SELECT * FROM ".TBL_ORGANIZATIONS." WHERE orgID='$orgID'");
						
						// Information in the update queue
						$updates = array(
							mysql_result($sql1, 0, 'orgName'), 
							mysql_result($sql1, 0, 'areaCode'), 
							mysql_result($sql1, 0, 'prefix'), 
							mysql_result($sql1, 0, 'lineNumber'), 
							mysql_result($sql1, 0, 'faxAreaCode'), 
							mysql_result($sql1, 0, 'faxPrefix'), 
							mysql_result($sql1, 0, 'faxLineNumber'), 
							mysql_result($sql1, 0, 'streetAddress'), 
							mysql_result($sql1, 0, 'streetAddress2'), 
							mysql_result($sql1, 0, 'city'), 
							mysql_result($sql1, 0, 'state'), 
							mysql_result($sql1, 0, 'zipCode'), 
							mysql_result($sql1, 0, 'websiteAddress'), 
							mysql_result($sql1, 0, 'email'), 
							mysql_result($sql1, 0, 'category'), 
							mysql_result($sql1, 0, 'BusinessIsInactive'));
						$updatersComment = mysql_result($sql1, 0, 'UpdatersComments');
						
						// Information in the database
						$orig = array(
							mysql_result($sql2, 0, 'orgName'), 
							mysql_result($sql2, 0, 'areaCode'), 
							mysql_result($sql2, 0, 'prefix'), 
							mysql_result($sql2, 0, 'lineNumber'), 
							mysql_result($sql2, 0, 'faxAreaCode'), 
							mysql_result($sql2, 0, 'faxPrefix'), 
							mysql_result($sql2, 0, 'faxLineNumber'), 
							mysql_result($sql2, 0, 'streetAddress'), 
							mysql_result($sql2, 0, 'streetAddress2'), 
							mysql_result($sql2, 0, 'city'), 
							mysql_result($sql2, 0, 'state'), 
							mysql_result($sql2, 0, 'zipCode'), 
							mysql_result($sql2, 0, 'websiteAddress'), 
							mysql_result($sql2, 0, 'email'), 
							mysql_result($sql2, 0, 'category'), 
							mysql_result($sql2, 0, 'Status'));
						
						// process the information need to update
						$array = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
						for($i = 0; $i < sizeof($array,0); $i++)
						{
							if(trim($updates[$i]) != trim($orig[$i]))
							{
								$array[$i] = 1;
							}
						}?>
						
                        <tr <?php if($array[0] == 1) echo 'class="false"'; ?>>
                        	<td>Org. Name</td>
                        	<td><?php echo $updates[0]; ?></td>
                            <td><input class="modEdit" type="text" name="orgName" value="<?php echo $orig[0]; ?>" /></td>
                        </tr>
                        <tr <?php if(($array[7] == 1)||($array[8] == 1)||($array[9] == 1)||($array[10] == 1)||($array[11] == 1)) echo 'class="false"'; ?>>
                        <?php 	$address1 = $updates[7]." ".$updates[8].", ".$updates[9].", ".$updates[10]." ".$updates[11];
								$address2 = $orig[7]." ".$orig[8].", ".$orig[9].", ".$orig[10]." ".$orig[11];?>
                            <td>Address</td>
                        	<td><a href="http://maps.google.com/?q=<?php echo $address1; ?>"><?php echo $address1; ?></a></td>
                            <td><input class="modEdit full" type="text" name="streetAddress" value="<?php echo $orig[7]; ?>" />
                            	<input class="modEdit full" type="text" name="streetAddress2" value="<?php echo $orig[8]; ?>" />
                                <input class="modEdit small" type="text" name="city" value="<?php echo $orig[9]; ?>" />
                                <input class="modEdit xxSmall" type="text" name="state" value="<?php echo $orig[10]; ?>" />
                                <input class="modEdit tiny" type="text" name="zipCode" value="<?php echo $orig[11]; ?>" /></td>
                        </tr>
                        <tr <?php if(($array[1] == 1)||($array[2] == 1)||($array[3] == 1)) echo 'class="false"'; ?>>
                        	<td>Phone</td>
                        	<td><?php echo "(".$updates[1].") ".$updates[2]."-".$updates[3]; ?></td>
                            <td>(<input class="modEdit xxSmall" type="text" name="areaCode" value="<?php echo $orig[1]; ?>" />)
								<input class="modEdit xxSmall" type="text" name="prefix" value="<?php echo $orig[2]; ?>" />-
								<input class="modEdit xSmall" type="text" name="lineNumber" value="<?php echo $orig[3]; ?>" /></td>
                        </tr>
                        <tr <?php if(($array[4] == 1)||($array[5] == 1)||($array[6] == 1)) echo 'class="false"'; ?>>
                        	<td>Fax</td>
                        	<td><?php echo "(".$updates[4].") ".$updates[5]."-".$updates[6]; ?></td>
                            <td>(<input class="modEdit xxSmall" type="text" name="faxAreaCode" value="<?php echo $orig[4]; ?>" />)
								<input class="modEdit xxSmall" type="text" name="faxPrefix" value="<?php echo $orig[5]; ?>" />-
								<input class="modEdit xSmall" type="text" name="faxLineNumber" value="<?php echo $orig[6]; ?>" /></td>
                        </tr>
                        <tr <?php if($array[12] == 1) echo 'class="false"'; ?>>
                        	<td>Website</td>
                        	<td><a href="<?php echo $updates[12];?>"><?php echo $updates[12]; ?></a></td>
                            <td><input class="modEdit" type="text" name="websiteAddress" value="<?php echo $orig[12]; ?>" /></td>
                        </tr>
                        <tr <?php if($array[14] == 1) echo 'class="false"'; ?>>
                        	<td>Category</td>
                        	<td><?php echo $updates[14]; ?></td>
                            <td><?php echo $orig[14]; ?></td>
                        </tr>
                        <tr <?php if($array[15] == 1) echo 'class="false"'; ?>>
                        	<td>Status</td>
                        	<td><?php if($updates[15] == 1){ echo "Active";} else{ echo "Inactive";} ?></td>
                            <td><?php if($orig[15] == 1){ echo "Active";} else{ echo "Inactive";} ?></td>
                        </tr>
                    </tbody>
                    <tfoot>
                        <tr style="visibility:hidden">
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                    </tfoot>
                </table>
                Comments:<br />
                <textarea id="comment" style="width:660px;" ><?php echo $updatersComment; ?></textarea>
            	<div id="update_footer">
                	<input type="hidden" name="moderator" value="1">
                    <input type="hidden" name="id" value="<?php echo $id; ?>" />
                    <input type="hidden" name="modEdit" value="1" />
                	<input class="button" type="submit" name="button" value="Confirm Changes" />
                    <input class="button" name="button" value="Cancel" onClick="parent.location='modView.php?id=<?php echo $id ?>&orgID=<?php echo $orgID ?>'" />
                    <!--<input class="button" type="submit" name="button" value="Delete Request" onclick="return confirm ('Are you sure you want to delete this update, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')" />
                    <input class="button" type="submit" name="button" value="Save Request" />-->
               	</div>
                <?php } ?>
			</ul>
		</form>
        </div>
	</div>
<?php include("footer.php"); ?>